package com.yugao.fintech.vctgone.admin.controller;

import com.yugao.fintech.vctgone.admin.pojo.dto.RegisteredClientDTO;
import com.yugao.fintech.vctgone.admin.pojo.vo.RegisteredClientVO;
import com.yugao.fintech.vctgone.admin.service.RegisteredClientService;
import com.yugao.fintech.vctgone.mybatisplus.base.BaseQuery;
import com.yugao.fintech.vctgone.mybatisplus.util.PageUtil;
import com.yugao.fintech.vctgone.web.util.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/client")
@Tag(name = "客户端管理")
@RequiredArgsConstructor
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegisteredClientController {
    private final RegisteredClientService registeredClientService;

    @GetMapping
    @Operation(summary = "获取客户端")
    @PreAuthorize("hasAuthority('sys_user_query')")
    public ResultVO<PageUtil<RegisteredClientVO>> getClients(BaseQuery query) {
        return ResultVO.success(registeredClientService.getClients(query));
    }

    @PostMapping
    @Operation(summary = "新增客户端")
    @PreAuthorize("hasAuthority('sys_user_add')")
    public ResultVO<?> saveClient(@RequestBody RegisteredClientDTO dto) {
        registeredClientService.saveOrUpdate(dto);
        return ResultVO.success();
    }

    @PutMapping
    @Operation(summary = "编辑客户端")
    @PreAuthorize("hasAuthority('sys_user_edit')")
    public ResultVO<?> updateClient(@RequestBody RegisteredClientDTO dto) {
        registeredClientService.saveOrUpdate(dto);
        return ResultVO.success();
    }

    @DeleteMapping("/{ids}")
    @Operation(summary = "删除客户端")
    @PreAuthorize("hasAuthority('sys_user_delete')")
    public ResultVO<?> delClient(@PathVariable String ids) {
        registeredClientService.delClient(ids);
        return ResultVO.success();
    }
}
